<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category SettingConfigPageController.php
 * @Depiction: 暂不开发
 * Author: hwy
 * Date: 2020/7/9  17:57
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Models\Setting;
use App\Services\SettingConfigService;
use App\Services\SettingConfigTabService;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

class SettingConfigPageController extends Controller
{

    protected $settingConfigService;

    protected $settingConfigTabService;

    protected $_model = 'setting_config_page';

    public function __construct()
    {
        $this->settingConfigService    = SettingConfigService::getInstance();
        $this->settingConfigTabService = SettingConfigTabService::getInstance();
    }

    /**
     * @param Request $request
     * @return Factory|View
     * @Depiction
     * @Author hwy
     * @Date  2020/10/10  19:36
     */
    public function index(Request $request)
    {
        $type   = $request->type != 0 ? $request->type : 0;
        $tab_id = $request->tab_id;
        if (empty($tab_id))
            $tab_id = 1;

        $list = $this->settingConfigService->getAll($tab_id);
        if ($type == 4) {//其他分类
            $config_tab = null;
        } else {
            $config_tab = $this->settingConfigService->getConfigTabAll($type);
            // foreach ($config_tab as $kk => $vv) {
            //     $arr = $this->settingConfigService->getAll($vv['value'])->toArray();
            //     if (empty($arr)) {
            //         unset($config_tab[$kk]);
            //     }
            // }
        }
        $compact = compact('request', 'list', 'config_tab', 'type', 'tab_id');

        return view('admin.' . $this->_model . '.index', $compact);
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @Depiction:
     * @Author: hwy
     * @Date: 2021/3/8  17:34
     */
    public function update(Request $request): JsonResponse
    {
        $responseData = $this->settingConfigService->editDataByName($request);

        return response()->json($responseData);
    }

}
